#include "app/LevelLoader.h"
#include <filesystem>
#include <fstream>
#include <algorithm>

std::vector<std::string> enumerateLevelFiles(const std::string& dir) {
    std::vector<std::string> paths;
    std::error_code ec;
    for (auto& entry : std::filesystem::directory_iterator(dir, ec)) {
        if (ec) break;
        if (!entry.is_regular_file()) continue;
        auto p = entry.path();
        if (p.extension() == ".txt") paths.push_back(p.string());
    }
    std::sort(paths.begin(), paths.end());
    return paths;
}

Level loadLevelFromFile(const std::string& path) {
    std::ifstream f(path);
    std::vector<std::string> lines;
    std::string s;
    while (std::getline(f,s)) { lines.push_back(s); }
    return Level::fromStringGrid(lines);
}